var pomelo = require('pomelo');
var bearcat = require("bearcat")
var fs = require("fs")
var contextPath = require.resolve('./context.json');
/**
 * Init app for client.
 */
var app = pomelo.createApp();
app.set('name', 'wasteSorting');
bearcat.createApp([contextPath],{ BEARCAT_HOT: "off"})
bearcat.start(function() {
  // app configuration
  app.configure('production|development', 'connector', function(){
    app.set('connectorConfig',
      {
        connector : pomelo.connectors.hybridconnector,
        heartbeat : 3,
        useDict : true,
        useProtobuf : true,
        // ssl: {
        //   type: 'wss',
        //   key: fs.readFileSync('./keys/yechenggame.key'),
        //   cert: fs.readFileSync('./keys/yechenggame.pem'),
        // }
      });
      app.filter(pomelo.filters.serial());
      //检测到node.js中事件循环的请求等待队列过长，超过一个阀值时，就会触发toobusy
      app.before(pomelo.filters.toobusy());
      //处理超时进行警告，默认三秒
      app.filter(pomelo.filters.timeout());
  });
  // start app
  app.start(function() {
    app.configure('production|development', 'connector', function(){
      var matchServer = bearcat.getBean("matchServer",app)
      app.set("matchServer",matchServer)
      var rankServer = bearcat.getBean("rankServer",app)
      app.set("rankServer",rankServer)
    });
    app.configure('production|development', 'master', function(){
      bearcat.getBean("httpServer")
    });
  });
})
process.on('uncaughtException', function (err) {
  console.error(' Caught exception: ' + err.stack);
});